package pkg

import (
	"go_zero_blog/models"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

func ConnectDB(args string) (db *gorm.DB, err error) {
	db, err = gorm.Open(mysql.Open(args), &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
	})
	return db, err
}

func AutoMigrate(db *gorm.DB) error {
	err := db.AutoMigrate(
		&models.Blog{},
		&models.User{},
	)
	return err
}
